"""
@name : 正则表达式
@author : shiyaling
@projectname : xsfh
"""
import requests
import re
######作业1

# #爬取页面的数据
response = requests.get("https://www.sanchuangedu.cn/")
response.encoding = "utf-8"
#print(response.text)
#抓取里面的图片信息
ret = re.findall(r"(?<=img src=\").+(?:jpg|png)",response.text)
# print(ret)
path = "F:\linux\picture"
#访问图片
a = 1
for i in ret:
    arr = ["https://www.sanchuangedu.cn/",i]
    url = ''.join(arr)
    # print(url)
    response2 = requests.get(url)
    dir = '图片'+str(a)+'.jpg'
    with open(dir,"wb") as f:
        f.write(response2.content)
        f.close()
        a += 1
print("保存完成")


#######作业2
# msg = "san chuang tong le, welcom ,'hello world' h1 h2 'sc1 sc2', 'xixi haha'learn python"
# # ret = re.findall("(?<=\').+?(?=\')|\w+",msg)
# # ret = re.findall('(?<=\')[a-zA-Z0-9 ]+(?=\')|(?<!\')[a-zA-Z0-9]+(?!\')',msg)
# ret = re.findall(r"(?<!\')\b\w+\b(?!\')|(?<=\').+?(?=\')",msg)
# ret = re.findall("\'(.+?)\'|(\w+)",msg)
# print(ret)



